<template>
	<view class="farmer-finance-index rel" v-if="isLoad">
		<view class="count-info flex-center flex-column c-base" :style="{background:primaryColor}">
			<view class="f-caption">可提余额(元)</view>
			<view class="price mt-sm">{{detail.cash}}</view>
			<view class="flex-center btn-list f-paragraph mt-lg pt-lg">
				<view @tap.stop="$util.goUrl({url:`/mine/pages/cash-out?type=farmer`})"
					class="item-child flex-center fill-base c-title mr-lg radius">提现</view>
				<view @tap.stop="$util.goUrl({url:`/farmer/pages/finance/record`})"
					class="item-child flex-center c-base radius">交易记录</view>
			</view>
		</view>
		<view class="money-count fill-base flex-center pt-lg pb-lg">
			<view class="item-child flex-center flex-column b-1px-r">
				<view class="flex-y-baseline f-lg-title">{{detail.total_cash}}</view>
				<view class="f-caption c-caption">总金额(元)</view>
			</view>
			<view class="item-child flex-center flex-column">
				<view class="flex-y-baseline f-lg-title">{{detail.frozen_cash}}</view>
				<view class="f-caption c-caption">实际冻结金额(元)</view>
			</view>
		</view>
		<view class="space-md"></view>
		<view class="fill-base pd-lg b-1px-b" v-for="(item,index) in list.data" :key="index">
			<view class="flex-between">
				<view class="max-446 ellipsis">{{item.order_code}}</view>
				<view class="f-title text-bold" :style="{color:index==0 ? primaryColor : '#FF5537'}">
					{{item.add==1?'+':'-'}} {{item.price}}
				</view>
			</view>
			<view class="flex-between f-caption c-desc mt-sm">
				<view class="c-caption">{{item.create_time_text}}</view>
				<view>{{item.type_text}}</view>
			</view>
		</view>

		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading" v-if="loading">
		</load-more>
		<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1"></abnor>

		<view class="space-footer"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex"
	import tabbar from "@/components/tabbar.vue"
	export default {
		components: {
			tabbar
		},
		data() {
			return {
				isLoad: false,
				detail: {},
				param: {
					page: 1,
				},
				list: {
					data: []
				},
				loading: true,
				lockTap: false
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			configInfo: state => state.config.configInfo,
			commonOptions: state => state.user.commonOptions,
			userInfo: state => state.user.userInfo,
		}),
		onLoad() {
			this.$util.setNavigationBarColor({
				color: '#ffffff',
				bg: '#39b54a'
			});
			this.$util.showLoading()
			this.initIndex()
		},
		onUnload() {
			this.$util.back()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		methods: {
			...mapMutations([]),
			async initIndex() {
				this.detail = await this.$api.farmer.farmerFinanceInfo()
				this.isLoad = true
				this.getList()
				this.$util.hideAll()
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex()
			},
			async getList() {
				let {
					list: oldList,
					param
				} = this
				let newList = await this.$api.farmer.farmerFinanceList(param);

				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			},
			handerTabChange(index) {
				this.activeIndex = index
				// this.$util.showLoading()
				// this.param.page = 1
				// this.list.data = []
				// this.getList()
			},
		}
	}
</script>


<style lang="scss">
	.farmer-finance-index {

		.count-info {
			height: 450rpx;

			.price {
				font-size: 70rpx;
			}

			.btn-list {
				.item-child {
					width: 240rpx;
					height: 64rpx;
					border: 1rpx solid #fff;
					transform: rotateZ(360deg);
				}
			}
		}

		.money-count {
			.item-child {
				width: 50%;
			}
		}
	}
</style>
